class Help

  VERBOSE_LEVEL = 3
  INFO_LEVEL = 2
  QUIET_LEVEL = 1
  NO_LEVEL = 0

  NO_HELP = 0
  
  UNKNOWN_DIRECTORY = 1000
  NO_DIRECTORY = 1001
  NO_REPOSITORY = 1002
  FLICKR_UPLOAD_FAILED = 1003
  UNKNOWN_FILE = 1004

  ADD_USAGE = 2000
  REPOSITORY_USAGE = 2001
  FLICKR_USAGE = 2002
  FLASH_USAGE = 2003
  COMPILE_USAGE = 2004
  
  BACKUP = 3001
  IGNORE = 3002
  REPOSITORY_CREATED = 3003
  BACKUP_COMPLETE = 3004
  BACKEDUP_FILE = 3005
  FLICKR_UPLOADED = 3006
  REQUEST_FLICKR_TOKEN = 3007
  COMPILE_COMPLETE = 3008
  FREEHAND_WELCOME = 3009
  FREEHAND_HELP = 3010
  FREEHAND_FINISH = 3011
  BACKUP_WELCOME = 3012
  BACKUP_INSTRUCTION = 3013

  attr_reader :id, :message, :level
  
  @@display_level = INFO_LEVEL

  #``````````````````
  # constructor
  #``````````````````

  def initialize(id,message,level = INFO_LEVEL)
    @id = id
    @message = message
    @level = level
    show_message if @@display_level >= level
  end
  
  def Help.display_level=(level)
    @@display_level = level
  end
  
  def Help.display_level
    @@display_level
  end
    
  def Help.no_help
    Help.new(NO_HELP,"",NO_LEVEL)
  end

  def Help.unknown_directory_for(directory)
    message = "Unknown directory #{directory}"
    Help.new(UNKNOWN_DIRECTORY,message)
  end

  def Help.no_directory
    Help.new(NO_DIRECTORY,"No directory provided")
  end
  
  def Help.no_repository
    Help.new(NO_REPOSITORY,"Please add some pictures, movies, etc before telling a story")
  end

  def Help.add_usage
    Help.new(ADD_USAGE,"Add usage: storyteller add <directory_name>\nExample: storyteller add /home/tmp")
  end

  def Help.repository_usage
    Help.new(REPOSITORY_USAGE,"Respository usage: storyteller new [<repository_name>]\nExample: storyteller new\nExample2: storyteller new aforward_story")
  end
  
  def Help.flickr_usage
    Help.new(FLICKR_USAGE,"Flickr upload usage: storyteller flickr [<picture_name>*]\nExample: storyteller flickr /TripA/1.jpg")
  end

  def Help.flash_usage
    Help.new(FLASH_USAGE,"Flash usage: storyteller flash <flash_filename> [<picture_directory>*]\nExample: storyteller flash movie.swf /TripA")
  end

  def Help.compile_usage
    Help.new(COMPILE_USAGE,"Compile usage: storyteller compile <grin_filename> <flash_filename> {<flash|smil>}\nExample: storyteller compile movie.grin movie.swf flash")
  end
  
  def Help.backup(b,number_of_files_added,number_of_files_removed = nil)
    backup_name = b.has_name? ? "#{b.name} " : ""

    searched_directories = ""
    b.directories.each { |directory| searched_directories += "+ #{directory}\n" }
    
    if number_of_files_removed.nil?
      message = "Adding media from #{backup_name}[#{b.root}]\n"
      message += searched_directories
      message += "Added #{Help.file_singular_or_plural(number_of_files_added)}"
    else
      message = "Updating media from #{backup_name}[#{b.root}]\n"
      message += searched_directories
      message += "Added #{Help.file_singular_or_plural(number_of_files_added)}, Removed #{Help.file_singular_or_plural(number_of_files_removed)}"
    end

      Help.new(BACKUP,message)
  end
  
  def Help.ignore(blah)
    Help.new(IGNORE,"Ignoring: [#{blah}]")
  end
  
  def Help.repository_created(name)
    Help.new(REPOSITORY_CREATED,"Created: [#{name}]")
  end

  def Help.backup_complete(dir,number_of_files)
    Help.new(BACKUP_COMPLETE,"Backup Complete\nDirectory: [#{dir}]\nFile(s): #{number_of_files}")
  end

  def Help.backedup_file(source_dir, dest_dir)
    Help.new(BACKEDUP_FILE,"Backed up [#{source_dir}] to [#{dest_dir}]",VERBOSE_LEVEL)
  end

  def Help.flickr_uploaded(number_of_files)
    Help.new(FLICKR_UPLOADED,"Uploaded #{Help.file_singular_or_plural(number_of_files)}",INFO_LEVEL)
  end

  def Help.request_flickr_token(url)
    Help.new(REQUEST_FLICKR_TOKEN,"Copy the following URL into your browser to authenticate with flickr:\n#{url}\nPress enter when you are finished")
  end

  def Help.flickr_upload_failed(error = nil)
    message = "Unable to upload photo to flickr"
    message += "\n#{error}" unless error.nil?
    Help.new(FLICKR_UPLOAD_FAILED,message)
  end

  def Help.unknown_file(filename)
    message = "Unknown file: [#{filename}]"
    Help.new(UNKNOWN_FILE,message)
  end

  def Help.compile_complete(infile,outfile)
    message = "Created #{outfile} (based on #{infile})"
    Help.new(COMPILE_COMPLETE,message)
  end  

  def Help.freehand_welcome
    message = "-----------------------\n" + 
              "CREATE YOUR MULTIMEDIA STORY\n" +
              "-- type [end] when complete\n" + 
              "-- type [help] for a list of story aides\n" + 
              "-----------------------"  
    Help.new(FREEHAND_WELCOME,message)
  end

  def Help.freehand_help
    message = "-----------------------\n" +
              "To write one line of text, just type\n" +
              "> Hello friends\n" +
              "\n" +
              "To write multiple lines of text,\n" +
              "> text\n" +
              "> All of this\n" +
              "> will be shown\n" +
              "> one multiple lines\n" +
              "> in one screen\n" +
              "> endtext\n" +
              "\n" +
              "To add an single image, specify the image directly\n" +
              "> image MyPictures/TripA/1.jpg MyPictures/TripA/2.jpg\n" +
              "\n" +
              "To add multiple images, specify a directory\n" +
              "> image MyPictures/TripC\n" +
              "\n" +
              "You can add multiple images, each separated by a space\n" +
              "> image MyPictures/TripD/1.jpg MyPictures/TripF\n" +
              "Back to your story!\n" +
              "-----------------------\n" 
    Help.new(FREEHAND_HELP,message)
  end

  def Help.freehand_finish
    Help.new(FREEHAND_FINISH,"-----------------------\n")
  end

  def Help.backup_welcome(backed_up_to_date, total)
    
    backup_up_mbs = backed_up_to_date / 1000000
    total_mbs = total / 1000000
  
    message = "-----------------------\n" +
              "BACKING UP YOUR CONTENT\n" + 
              "-- #{backup_up_mbs} mbs of #{total_mbs} mbs backedup\n" +
              "-----------------------\n" 
    Help.new(BACKUP_WELCOME,message)
  end
  
  def Help.backup_instruction(where)
    message = "Where are you backing up to?"
    unless where.nil?
      message += " (leave blank to keep #{where}, type [end] to stop)"
    end
    message += "\n";
    Help.new(BACKUP_INSTRUCTION,message)
  end

  def show_message
    puts @message unless @level == NO_LEVEL
  end
  
  
  private 
  
    def Help.file_singular_or_plural(number_of_files)
      number_of_files == 1 ? "1 file" : "#{number_of_files} files"    
    end


end
